package com.winning.devops.batch.writer.ch04.config;

import com.winning.devops.batch.writer.ch04.domain.Customer;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * xml 文件配置
 *
 * @author chensj
 * @date 2020-03-07 18:10
 */
@Configuration
public class XmlFileWriterJobConfig {

    @Autowired
    private JobBuilderFactory jobBuilderFactory;
    @Autowired
    private StepBuilderFactory stepBuilderFactory;
    @Autowired
    @Qualifier("xmlFileItemDemoReader")
    private ItemReader<? extends Customer> xmlFileItemDemoReader;
    @Autowired
    @Qualifier("xmlFileItemDemoWriter")
    private ItemWriter<? super Customer> xmlFileItemDemoWriter;

    @Bean
    public Job xmlFileWriterDemoJob() {
        return jobBuilderFactory.get("xmlFileWriterDemoJob")
                .start(xmlFileWriterDemoStep())
                .build();
    }

    @Bean
    public Step xmlFileWriterDemoStep() {
        return stepBuilderFactory.get("xmlFileWriterDemoStep")
                .<Customer, Customer>chunk(10)
                .reader(xmlFileItemDemoReader)
                .writer(xmlFileItemDemoWriter)
                .build();
    }
}
